07. Truncation

Truncation

ND079 C1 L1 A06 Truncation

Truncation is a loss of precision when going from one to type to another. Basically, we are cutting off or "truncating" the additional data.

Note that this is not the same thing as rounding. For example, if we round 3.9, we get 4.0. But if we truncate 3.9, we get simply 3! Truncation simply removes the additional data that will not fit, which is why it results in a loss of precision.

When does truncation occur?

SOLUTION: When doing **manual type casting** to convert a **larger type to a smaller type**

Truncation occurs becauseā€¦

SOLUTION: Smaller types allocate less memory than larger types